package com.mm.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mm.entity.MmLog;
import com.mm.mapper.MmLogMapper;
import com.mm.service.IMmLogService;
import com.mm.entity.MmBaseLog;
import com.mm.system.service.SysContext;
import com.mm.utils.ServletUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * <p>
 * 日志表 服务实现类
 * </p>
 *
 * @author wdx
 * @since 2021-03-04
 */
@Service
public class MmLogServiceImpl extends ServiceImpl<MmLogMapper, MmLog> implements IMmLogService, SysContext {

    @Override
    public Boolean saveLog(MmBaseLog baseLog) {
        MmLog mmLog = new MmLog();
        BeanUtils.copyProperties(baseLog,mmLog);
        mmLog.setOperateAddress(ServletUtil.getRemoteHost());
        mmLog.setMethod(ServletUtil.getRequestURI());
        mmLog.setRequestMethod(RequestMethod.valueOf(ServletUtil.getMethod()));
        mmLog.setOperateUrl(ServletUtil.getRequestURI());
        mmLog.setBrowser(ServletUtil.getBrowser());
        //查询参数
        mmLog.setRequestParam(ServletUtil.getQueryParam());
        mmLog.setSystemOs(ServletUtil.getSystem());
        return save(mmLog);
    }
}
